package yuan.productservice9998.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/09/17 17:01
 */

@RestController
@RequestMapping("/product")
public class HeloController {

    @Value("${server.port}")
    private int port;
    @GetMapping("/showProduct")
    public String getProduct(){



        return "进入商品服务，展示商品~ port: "+port;
    }


    @GetMapping("/showProductParam")
    public String getProduct(String id){

        return "进入商品服务，展示商品~ port: " + port + "id: " + id;
    }


    @GetMapping("/hystrixtest1")
    @HystrixCommand(fallbackMethod = "hystrixtest1FallBack")
    public String hystrixtest1(int id){

        if(id<1)
            throw new RuntimeException("id错误！");

        return "进入商品服务，展示商品~ port: " + port + "id: " + id;
    }

    @GetMapping("/hystrixtest2")
    @HystrixCommand(defaultFallback = "defaultFallback")
    public String hystrixtest2(int id){

        if(id<1)
            throw new RuntimeException("id错误！");

        return "进入商品服务，展示商品~ port: " + port + "id: " + id;
    }


    public String hystrixtest1FallBack(int id){


        return "触发熔断 id： " + id;
    }

    public String defaultFallback(){


        return "触发默认熔断！";
    }
}
